/*
 *  Copyright 2010 dmakariev.
 * 
 */
package org.deltaset.secured.upload;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.ManagedBean;
import org.deltaset.faces.upload.CurrentFile;
import org.deltaset.faces.upload.FileRequestHolder;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.WebApplicationContext;

/**
 *
 * @author dmakariev
 */
@ManagedBean("uploadBean")
@Scope(WebApplicationContext.SCOPE_SESSION)
public class UploadBean implements Serializable {

    private static final long serialVersionUID = 4565624335526566769L;
    private static final Logger logger = Logger.getLogger(UploadBean.class.getName());
    private String authorName;
    private CurrentFile currentFile = null;            

    public void showResult() {       
        logger.log(Level.INFO, " ~~~~~~~~~~~~~~authorName={0}", authorName);       
    }
    
    public void showResultAjax(){
        this.authorName="ajax author";
    }

    /**
     * @return the authorName
     */
    public String getAuthorName() {
        return authorName;
    }

    /**
     * @param authorName the authorName to set
     */
    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    /**
     * @return the currentFile
     */
    public CurrentFile getCurrentFile() {
        if(null!=currentFile){
            logger.log(Level.INFO, "getCurrentFile currentFile.getName()={0}", currentFile.getName());
            logger.log(Level.INFO, "getCurrentFile currentFile.getContentType()={0}", currentFile.getContentType());
        }
        return currentFile;
    }

    /**
     * @param currentFile the currentFile to set
     */
    public void setCurrentFile(CurrentFile currentFile) {      
        logger.log(Level.INFO, "setCurrentFile currentFile.isNull={0}", (null == currentFile));
        if(null!=currentFile){          
            logger.log(Level.INFO, "setCurrentFile currentFile.getName()={0}", currentFile.getName());
        }
        this.currentFile = currentFile;
    }

    public boolean getIsEmpty() {
        return FileRequestHolder.isEmpty();
    }
}
